package com.example.demo.config.service.impl;

import com.alibaba.fastjson.JSON;
import com.example.demo.common.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.springframework.stereotype.Service;

/**
 * @author yongen
 * @description: 处理MQ消息-添加用户
 * @date 2022/2/9 3:12 PM
 */
@Service("addUserHandler")
@Slf4j
public class AddUserHandler extends AbstarctRocketMQConsumerServiceImpl {

  @Override
  public ConsumeConcurrentlyStatus handle(String message) {
    log.info("mq消息处理开始【添加用户】，message={}", message);
    try {
      UserDTO user = JSON.parseObject(message, UserDTO.class);
      // 模拟做业务操作
      // ....
      System.out.println(user.toString());
    } catch (Exception e) {
      log.error("handler error:{}", e.getMessage());
      return ConsumeConcurrentlyStatus.RECONSUME_LATER;
    }
    return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
  }
}
